<template>
  <div class="home">
    <!-- 筛选 -->
    <div class="search_content">
      <div class="task_header">
        <div class="top_title">
          <div class="top_title_back" @click="onClickLeft">
            <i class="iconfont icon-back"></i>
          </div>
          <div class="top_title_val">{{ $route.meta.title }}</div>
        </div>

        <div class="top_search">
          <div class="top_search_val">
            <form action>
              <van-search v-model="requestParams.codeNo" placeholder="请输入车架号或者车牌号" shape="round" @search="initData" @clear="clearSearch" />
            </form>
          </div>
          <div class="top_search_icon">
            <img @click="handleShowSearch" src="@/assets/images/search_bg.png" />
          </div>
        </div>
      </div>
    </div>
    <!-- 搜索弹窗 -->
    <div class="search_info" v-if="searchVisible">
      <div class="pop_content">
        <div class="popSearch">
          <div class="popSearchbox">
            <div class="popSearchbox_item">
              <div class="popSearch_tt">进场时间</div>
              <div class="popSearch_time">
                <div class="popSearch_time_txt" @click="handleSelectTime('startDateIn')">
                  <input v-model="requestParams.startDateIn" class="popSearch_time_val" placeholder="开始时间" readonly />
                </div>
                <span class="popSearch_time_icon">-</span>
                <div class="popSearch_time_txt" @click="handleSelectTime('endDateIn')">
                  <input v-model="requestParams.endDateIn" class="popSearch_time_val" placeholder="结束时间" readonly />
                </div>
              </div>
            </div>
            <div class="popSearchbox_item">
              <div class="popSearch_tt">完工时间</div>
              <div class="popSearch_time">
                <div class="popSearch_time_txt" @click="handleSelectTime('startFinishDate')">
                  <input v-model="requestParams.startFinishDate" class="popSearch_time_val" placeholder="开始时间" readonly />
                </div>
                <span class="popSearch_time_icon">-</span>
                <div class="popSearch_time_txt" @click="handleSelectTime('endFinishDate')">
                  <input v-model="requestParams.endFinishDate" class="popSearch_time_val" placeholder="结束时间" readonly />
                </div>
              </div>
            </div>
            <div class="popSearchbox_item">
              <div class="popSearch_tt">结算时间</div>
              <div class="popSearch_time">
                <div class="popSearch_time_txt" @click="handleSelectTime('startSettleTime')">
                  <input v-model="requestParams.startSettleTime" class="popSearch_time_val" placeholder="开始时间" readonly />
                </div>
                <span class="popSearch_time_icon">-</span>
                <div class="popSearch_time_txt" @click="handleSelectTime('endSettleTime')">
                  <input v-model="requestParams.endSettleTime" class="popSearch_time_val" placeholder="结束时间" readonly />
                </div>
              </div>
            </div>

            <div class="popSearchbox_item">
              <div class="popSearch_tt">工单类型</div>
              <div class="popSearchbox_selectList">
                <div
                  class="popSearchbox_select_item"
                  :class="item.check ? 'active' : ''"
                  v-for="(item, index) in workBillTypeList"
                  :key="index"
                  @click="handleSearchSelect(index, 'workBillTypeList', 'workBillType')"
                >
                  {{ item.name }}
                </div>
              </div>
            </div>

            <div class="popSearchbox">
              <div class="popSearchbox_item">
                <div class="popSearch_tt">所属服务顾问</div>
                <van-field
                  v-model="requestParams.fixCenterName"
                  name="维修中心"
                  label="维修中心"
                  input-align="right"
                  placeholder="请选择"
                  readonly
                  right-icon="arrow"
                  @click="handleSelect('fixCenterId', 'fixCenterName')"
                />

                <van-field
                  v-model="requestParams.serverPsnName"
                  name="服务顾问"
                  label="服务顾问"
                  input-align="right"
                  placeholder="请选择"
                  readonly
                  right-icon="arrow"
                  @click="handleSelect('serverPsnId', 'serverPsnName')"
                />
              </div>
            </div>
          </div>

          <div class="popSearch_footer">
            <div class="popSearch_btn reset_btn" @click.stop="handleSearchReset">重置</div>
            <div class="popSearch_btn save_btn" @click.stop="handleSearchSave">保存方案</div>
            <div class="popSearch_btn confirm_btn" @click.stop="handleSearchConfirm">确认</div>
          </div>
        </div>
      </div>
      <div class="mask" @click="searchVisible = false"></div>
    </div>
    <!-- <div class="search_content">
      <van-nav-bar
        :title="$route.meta.title"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
      <van-search
        v-model="requestParams.codeNo"
        placeholder="请输入车架号或者车牌号"
        shape="round"
        @search="initData"
        @clear="clearSearch"
      />
      <div class="search_item">
        <van-dropdown-menu :close-on-click-outside="false">
          <van-dropdown-item title="工单类型" ref="workRef">
            <div class="searchbox">
              <div class="insureList">
                <div
                  class="insure_item"
                  :class="item.check ? 'active' : ''"
                  v-for="(item, index) in workBillTypeList"
                  :key="index"
                  @click="handleWorkSelect(index)"
                >
                  {{ item.name }}
                </div>
              </div>
              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleWorkReset()"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('workRef')"
                >
                  确认
                </van-button>
              </div>
            </div>
          </van-dropdown-item>

          <van-dropdown-item title="所属服务顾问" ref="insureRef">
            <div class="searchbox">
              <van-field
                v-model="requestParams.fixCenterName"
                name="维修中心"
                label="维修中心"
                input-align="right"
                placeholder="请选择"
                readonly
                right-icon="arrow"
                @click="handleSelect('fixCenterId', 'fixCenterName')"
              />
              <van-field
                v-model="requestParams.serverPsnName"
                name="服务顾问"
                label="服务顾问"
                input-align="right"
                placeholder="请选择"
                readonly
                right-icon="arrow"
                @click="handleSelect('serverPsnId', 'serverPsnName')"
              />

              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleReset()"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('insureRef')"
                >
                  确认
                </van-button>
              </div>
            </div>
          </van-dropdown-item>

          <van-dropdown-item title="筛选" ref="statusRef">
            <div class="searchbox timebox">
              <div class="title">进场时间</div>
              <div class="flex">
                <van-field
                  class="time_item"
                  v-model="requestParams.startDateIn"
                  label=""
                  :placeholder="'开始时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('startDateIn')"
                />
                -
                <van-field
                  class="time_item"
                  v-model="requestParams.endDateIn"
                  label=""
                  :placeholder="'结束时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('endDateIn')"
                />
              </div>
              <div class="title">完工时间</div>

              <div class="flex">
                <van-field
                  class="time_item"
                  v-model="requestParams.startFinishDate"
                  label=""
                  :placeholder="'开始时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('startFinishDate')"
                />
                -
                <van-field
                  class="time_item"
                  v-model="requestParams.endFinishDate"
                  label=""
                  :placeholder="'结束时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('endFinishDate')"
                />
              </div>
              <div class="title">结算时间</div>

              <div class="flex">
                <van-field
                  class="time_item"
                  v-model="requestParams.startSettleTime"
                  label=""
                  :placeholder="'开始时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('startSettleTime')"
                />
                -
                <van-field
                  class="time_item"
                  v-model="requestParams.endSettleTime"
                  label=""
                  :placeholder="'结束时间'"
                  input-align="right"
                  readonly
                  @click="handleSelectTime('endSettleTime')"
                />
              </div>

              <div class="insureBtn">
                <van-button
                  size="small"
                  type="warning"
                  class="resetBtn"
                  @click="handleSelectReset()"
                >
                  重置
                </van-button>
                <van-button
                  size="small"
                  type="info"
                  class="confirmBtn"
                  @click="onConfirm('statusRef')"
                >
                  确认
                </van-button>
              </div>
            </div>
          </van-dropdown-item>
        </van-dropdown-menu>

      </div>
    </div>-->
    <van-popup v-model="showSelectPicker" position="bottom">
      <van-field
        name="模糊查询"
        input-align="left"
        v-model="likeWho"
        label="模糊查询"
        v-if="likeWhoField == 'fixCenterId' || likeWhoField == 'serverPsnId'"
        placeholder="请输入模糊查询关键词"
      />
      <van-picker show-toolbar :columns="columns" @confirm="handleSelectConfirm" @cancel="showSelectPicker = false" value-key="name" />
    </van-popup>

    <van-popup v-model="showPickerDate" position="bottom">
      <van-datetime-picker v-model="currentDate" type="date" @cancel="onCancelDate" @confirm="onConfirmDate" :formatter="formatter" />
    </van-popup>

    <!-- 列表 -->
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="loadData" v-if="recordList && recordList.length != 0">
        <div class="orderList">
          <div class="orderbox" v-for="(item, index) in recordList" :key="index">
            <div class="flex">
              <div class="orderItem" @click="goDetail(item)">
                <div class="orderItem_box">
                  <div class="orderItem_header">
                    <div class="orderItem_lt">
                      <div class="carNo">
                        <div class="carNobox">
                          <div class="txt">{{ item.carNo }}</div>
                        </div>
                        <span :class="item.billStatus == '保存' ? 'carStatus' : 'noCarStatus'">{{ item.billStatus }}</span>
                      </div>
                      <div class="vinNobox">
                        <div class="vinNo" v-if="item.vinCode">
                          {{ item.vinCode }}
                          <i @click.stop="handleCopy(item.vinCode)" class="iconfont icon-copy"></i>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="orderItem_content">
                  <div class="orderItem_data w65">
                    <div class="order_label">所属服务顾问：</div>
                    <div class="txt">{{ item.empName ? item.empName : '暂无' }}</div>
                  </div>
                  <div class="orderItem_data w35">
                    <div class="order_label">工单类型：</div>
                    <div class="txt">{{ item.workBillType ? item.workBillType : '暂无' }}</div>
                  </div>
                  <div class="orderItem_data w65">
                    <div class="order_label">车型：</div>
                    <div class="txt">{{ item.carModel ? item.carModel : '暂无' }}</div>
                  </div>
                  <div class="orderItem_data w35">
                    <div class="order_label">实际进场时间：</div>
                    <div class="txt">{{ item.dateIn ? item.dateIn : '暂无' }}</div>
                  </div>
                </div>
                <div class="orderItem_content orderItem_footer">
                  <div class="orderItem_data w65">
                    <div class="order_label">客户：</div>
                    <div class="txt">{{ item.customerName ? item.customerName : '暂无' }}</div>
                  </div>
                  <div class="item_icon">
                    <img class="item_img" src="@/assets/images/wechat_icon.png" @click.stop="getExList(item)" />
                    <img class="item_img" src="@/assets/images/tel_icon.png" @click.stop="handleTel(item.tel)" />
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- <div
          class="orderList"
          v-if="recordList && recordList.length != 0"
        >
          <div
            class="orderItem"
            v-for="(item, index) in recordList"
            :key="index"
          >
            <div class="orderItem_box">
              <div class="orderItem_header">
                <div
                  class="orderItem_lt"
                  @click="goDetail(item)"
                >
                  <div class="carNo">{{ item.carNo }}</div>
                  <div class="carStatus">{{ item.billStatus }}</div>
                </div>
                <div class="orderItem_rt">
                  <a @click="handleTel(item.tel)">
                    <i class="iconfont icon-tel"></i>
                  </a>
                  <div
                    class="iconfont icon-wx"
                    @click.stop="getExList(item)"
                  ></div>
                </div>
              </div>
              <div class="vinNo">{{ item.vinCode }}</div>
            </div>

            <div
              class="orderItem_content"
              @click="goDetail(item)"
            >
              <div class="orderItem_data">
                <div class="order_label">客户名称</div>
                <div class="txt">{{ item.customerName }}</div>
              </div>
              <div class="orderItem_data">
                <div class="order_label">所属服务顾问</div>
                <div class="txt">{{ item.empName }}</div>
              </div>
              <div class="orderItem_data">
                <div class="order_label">车型</div>
                <div class="txt">{{ item.carModel }}</div>
              </div>
              <div class="orderItem_data">
                <div class="order_label">工单类型</div>
                <div class="txt">{{ item.workBillType }}</div>
              </div>
              <div class="orderItem_data time">
                <div class="order_label">实际进场时间</div>
                <div class="txt">{{ item.dateIn }}</div>
              </div>
            </div>
          </div>
        </div>-->
      </van-list>
      <div class="no_icon" v-else>
        <img class="no_icon_img" src="@/assets/images/no_icon.png" />
        <div class="no_icon_txt">暂无内容</div>
      </div>
    </van-pull-refresh>

    <div class="loading" v-if="loading">
      <van-loading size="30px" class="loadbox" color="#fff" text-color="#fff">加载中...</van-loading>
      <div class="mask"></div>
    </div>
    <van-dialog v-model="showDialog" title show-cancel-button :showConfirmButton="false">
      <div class="contact_list">
        <div class="contact_item flex" v-for="(item, index) in contactList" :key="index">
          <div class="contact_lt flex">
            <img v-if="item.avatar" class="contact_header" :src="item.avatar" />
            <div class="contact_name">{{ item.remark ? item.remark : item.name }}</div>
            <div class="contact_com_wx" v-if="item.type == 1">@微信</div>
            <div class="contact_com" v-if="item.type == 2">@{{ item.corpName ? item.corpName : item.corpFullName }}</div>
          </div>
          <div class="contact_btn" @click="runWxChat(item)">联系</div>
        </div>
      </div>
    </van-dialog>
  </div>
</template>

<script>
import { Dialog, DropdownItem, DropdownMenu, Empty, Loading, Notify, Search, Toast } from 'vant'
import repairApi from '@/api/repairApi'
import { copyToClipboard, getCookies, getLastTimeYMD, getTimeYMD, isPhone } from '../../utils/util'
import commonApi from '@/api/commonApi'
import axios from 'axios'
import qs from 'qs'

const base_url = process.env.BASE_API
export default {
  name: 'repairOrder',
  components: {
    Search,
    DropdownMenu,
    DropdownItem,
    Empty,
    Dialog,
    Toast,
    Loading,
    Notify,
  },
  data() {
    return {
      value: '',
      carCouponList: [
        { name: '是', code: 1, check: false },
        { name: '否', code: 0, check: false },
      ],
      showPickerDate: false,
      showPickerDate1: false,
      currentDate: new Date(),
      currentDate1: new Date(),

      recordList: [
        // {
        //   billId: '1', //单据ID
        //   vinCode: '123', //车架号
        //   carNo: '闽D12312', //车牌号
        //   customerName: '张三', //客户名称
        //   billStatus: '申请结算', //单据类型
        //   mobile1: '18921312312', //手机号1
        //   mobile12: '', //手机号2
        //   empName: '张三', //所属服务顾问
        //   carModel: '保时捷', //车型
        //   workBillType: '精品美容', //工单类型
        //   dateIn: '2023-08-09', //预约进场时间,
        // },
      ],
      columns: [],
      showSelectPicker: false,
      requestParams: {
        codeNo: '', //车架号或者车牌号，String，必填
        pageNo: 1, //当前页数，默认从1开始，每页显示十条，int，不能为空或者小于1
        startDateIn: getLastTimeYMD(), //进场开始时间，日期yyyy-MM-dd
        endDateIn: getTimeYMD(), //进场结束时间，日期yyyy-MM-dd
        startFinishDate: '', //完工开始时间，日期yyyy-MM-dd
        endFinishDate: '', //完工结束时间，日期yyyy-MM-dd
        startSettleTime: '', //结算开始时间，日期yyyy-MM-dd
        endSettleTime: '', //结算结束时间，日期yyyy-MM-dd
        workBillType: '', //工单类型，枚举
        serverPsnId: '', //维修中心ID
        serverPsnName: '', //维修中心ID
        fixCenterId: '', //服务顾问ID
        fixCenterName: '',
        userId: getCookies('userId'), //用户ID，必填，String
        personOrOrgId: '',
      },
      carCouponIndex: null,
      timeField: '',
      // 分页参数
      loading: false,
      finished: false,
      refreshing: false,
      isLoadData: false,
      workBillTypeList: [],
      field: '',
      fieldName: '',
      fixCenterList: [],
      empList: [],
      showDialog: false,
      contactList: [],
      likeWhoField: '',
      likeWho: '',
      searchVisible: false,
    }
  },
  watch: {
    likeWho: function (nval, oval) {
      if (this.likeWhoField == 'fixCenterId') {
        if (nval) {
          let newArr = this.fixCenterList.filter((item) => {
            return item.name.indexOf(nval) > -1
          })
          console.log(newArr)
          this.columns = newArr
        } else {
          this.columns = this.fixCenterList
        }
      }

      if (this.likeWhoField == 'serverPsnId') {
        if (nval) {
          let newArr = this.empList.filter((item) => {
            return item.name.indexOf(nval) > -1
          })
          console.log(newArr)
          this.columns = newArr
        } else {
          this.columns = this.empList
        }
      }
    },
    searchVisible: function (val, oVal) {
      if (val) {
        document.body.style.overflow = 'hidden'
      } else {
        document.body.style.overflow = ''
      }
    },
  },
  activated() {
    this.initData()
  },
  mounted() {
    this.getWorkBillType()
    this.getMainFixCenter()
    if (localStorage.getItem('repairOrderParam')) {
      this.repairOrderParam = JSON.parse(localStorage.getItem('repairOrderParam'))
      this.requestParams.personOrOrgId = this.repairOrderParam.personOrOrgId
      this.requestParams.startDateIn = ''
      this.requestParams.endDateIn = ''
    } else {
      if (localStorage.getItem('repairSearchParam')) {
        this.requestParams = JSON.parse(localStorage.getItem('repairSearchParam'))
      }
    }
    this.initData()
  },

  methods: {
    // 回显缓存的参数
    showStorgeParam(listField, field, fieldName) {
      let repairSearchParam = JSON.parse(localStorage.getItem('repairSearchParam'))
      if (field == 'fixCenterId') {
        this.getEmpPerson()
      }
      this[listField] &&
        this[listField].forEach((item, index) => {
          if (field == 'fixCenterId' || field == 'serverPsnId') {
            if (item.billId == repairSearchParam[field]) {
              this.requestParams[fieldName] = item.name
            }
          } else {
            let arr = repairSearchParam[field].split(';')
            arr &&
              arr.forEach((el, ei) => {
                if (item.value == el) {
                  item.check = true
                }
              })
          }
        })
    },
    // 回显其他筛选
    showStorgeOtherParam() {
      let policySearchParam = JSON.parse(localStorage.getItem('repairSearchParam'))
      this.otherList.forEach((item, index) => {
        if (policySearchParam[item.field]) {
          item.check = true
        }
      })
    },
    // 获取外部联系人信息
    getExList(data) {
      axios({
        url: `${base_url}/proxy/ext/user/getExList`,
        method: 'post',
        data: qs.stringify(
          // { url: 'http://wycl.autocnd.com:41080/ysc/assessManageDetail' },
          { carNo: data.carNo, name: data.customerName },
          { encode: false }
        ),
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          satoken: getCookies('token'),
        },
      }).then((res) => {
        if (res.data && res.data.data && res.data.data.length != 0) {
          this.contactList = res.data.data
          this.showDialog = true
        } else {
          Toast('未找到相关联系人')
        }

        console.log('获取外部联系人信息:', res)
      })
    },
    runWxChat(data) {
      let vm = this
      axios({
        url: `${base_url}/proxy/qywx/jsdkConfig`,
        method: 'post',
        data: qs.stringify(
          // { url: 'http://wycl.autocnd.com:41080/ysc/assessManageDetail' },
          { url: location.href.split('?')[0], type: 'app' },
          { encode: false }
        ),
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          satoken: getCookies('token'),
        },
      }).then((res) => {
        console.log('jsdkConfig:', res)
        let jsdk = res.data.data
        localStorage.setItem('jsdk', JSON.stringify(res.data.data))
        wx.agentConfig({
          corpid: jsdk.corpid, // 必填，企业微信的corpid，必须与当前登录的企业一致
          agentid: jsdk.agentid, // 必填，企业微信的应用id （e.g. 1000247）
          timestamp: jsdk.timestamp, // 必填，生成签名的时间戳
          nonceStr: jsdk.nonceStr, // 必填，生成签名的随机串
          signature: jsdk.signature, // 必填，签名，见附录-JS-SDK使用权限签名算法
          jsApiList: ['openEnterpriseChat'], //必填，传入需要使用的接口名称
          success: function (res) {
            console.log('agentConfig权限成功返回信息:', res)
            wx.openEnterpriseChat({
              // 注意：userIds和externalUserIds至少选填一个。内部群最多2000人；外部群最多500人；如果有微信联系人，最多40人
              userIds: '', //参与会话的企业成员列表，格式为userid1;userid2;...，用分号隔开。
              externalUserIds: data.externalUserid, // 参与会话的外部联系人列表，格式为userId1;userId2;…，用分号隔开。
              groupName: '', // 会话名称。单聊时该参数传入空字符串""即可。
              chatId: '', // 若要打开已有会话，需指定此参数。如果是新建会话，chatId必须为空串
              success: function (res) {
                var chatId = res.chatId //返回当前群聊ID，仅当使用agentConfig注入该接口权限时才返回chatId
                // 回调
              },
              fail: function (res) {
                if (res.errMsg.indexOf('function not exist') > -1) {
                  alert('版本过低请升级')
                }
              },
            })
          },
          fail: function (res) {
            console.log('agentConfig权限失败返回信息:', res)
            if (res.errMsg.indexOf('function not exist') > -1) {
              alert('版本过低请升级')
            }
          },
        })
      })
    },

    // 初始化列表
    initData() {
      this.requestParams.pageNo = 1
      this.loadData()
    },
    // 获取列表
    loadData() {
      if (this.isLoadData) return
      this.isLoadData = true
      this.loading = true
      this.finished = false
      // console.log(this.isLoadData);
      repairApi
        .queryRepairWorkOrder({ ...this.requestParams })
        .then((res) => {
          if (res) {
            if (this.requestParams.pageNo == 1) {
              this.recordList = res.data || []
            } else {
              this.recordList = this.recordList.concat(res.data || [])
            }
            this.requestParams.pageNo += 1

            if (res.data.length < 10) {
              this.finished = true
              this.isLoadData = true
            }
            this.isLoadData = false
            this.loading = false
          }
        })
        .catch((res) => {
          this.isLoadData = false
          this.loading = false
        })
    },
    // 下拉刷新
    onRefresh() {
      // 清空列表数据
      this.recordList = []
      this.finished = false
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.refreshing = false
      this.initData()
    },

    // 获取工单类型
    getWorkBillType() {
      commonApi
        .getEnums({
          key: 'workBillTypeNew',
          userId: this.requestParams.userId,
        })
        .then((res) => {
          if (res.data) {
            this.workBillTypeList = this.formatCheckData(res.data)
            if (localStorage.getItem('repairSearchParam') && localStorage.getItem('repairSearchParam') != '{}') {
              this.showStorgeParam('workBillTypeList', 'workBillType')
            }
          }
        })
    },
    // 获取维修中心
    getMainFixCenter() {
      commonApi
        .getMainFixCenter({
          userId: this.requestParams.userId,
          type: 'fixCenter',
        })
        .then((res) => {
          if (res.data) {
            this.fixCenterList = res.data
            if (localStorage.getItem('repairSearchParam') && localStorage.getItem('repairSearchParam') != '{}') {
              this.showStorgeParam('fixCenterList', 'fixCenterId', 'fixCenterName')
            }
          }
        })
    },
    // 获取服务人员
    getEmpPerson() {
      commonApi
        .getEmpPerson({
          fixCenterId: this.updateServiceVisible ? this.updateServiceData.fixCenterId : this.requestParams.fixCenterId,
          userId: this.requestParams.userId,
        })
        .then((res) => {
          if (res.data) {
            this.empList = res.data
            this.showStorgeParam('empList', 'serverPsnId', 'serverPsnName')
          }
        })
    },

    // 选择下拉
    handleSelect(field, fieldName) {
      if (field == 'carCoupon') {
        this.columns = [
          { name: '是', value: 1 },
          { name: '否', value: 2 },
        ]
      } else if (field == 'serverPsnId') {
        if (!this.requestParams.fixCenterId) {
          Toast('请先选择维修中心')
          return
        }
        this.columns = this.empList
      } else if (field == 'fixCenterId') {
        this.columns = this.fixCenterList
      }
      this.field = field
      this.fieldName = fieldName
      this.showSelectPicker = true
      this.likeWhoField = field
    },

    // 筛选重置
    handleSelectReset() {
      this.requestParams.startDateIn = ''
      this.requestParams.endDateIn = ''
      this.requestParams.startFinishDate = ''
      this.requestParams.endFinishDate = ''
      this.requestParams.startSettleTime = ''
      this.requestParams.endSettleTime = ''
    },

    // 选择下拉确认
    handleSelectConfirm(value, index) {
      this.requestParams[this.field] = value.billId
      this.requestParams[this.fieldName] = value.name
      if (this.field == 'fixCenterId') {
        this.requestParams.serverPsnId = ''
        this.requestParams.serverPsnName = ''
        this.getEmpPerson()
      }
      this.likeWho = ''
      this.showSelectPicker = false
    },

    // 所属服务顾问重置
    handleReset() {
      console.log(111)
      this.requestParams.fixCenterId = ''
      this.requestParams.fixCenterName = ''
      this.requestParams.serverPsnId = ''
      this.requestParams.serverPsnName = ''
    },

    onConfirm(ref) {
      let arr = []
      if (ref == 'workRef') {
        this.workBillTypeList.forEach((item, index) => {
          if (item.check) {
            arr.push(item.value)
          }
        })
        this.requestParams.workBillType = arr.join(';')
      }
      this.initData()
      this.$refs[ref].toggle()
    },

    // 日期组件自定义格式
    formatter(type, value) {
      if (type === 'year') {
        this.value1 = value // 可以拿到当前点击的数值
        return `${value}年`
      } else if (type === 'month') {
        this.value2 = value
        return `${value}月`
      }
      this.value3 = value
      return `${value}日`
    },

    // 获取list名称
    getFieldName(list, key, val) {
      if (list && list.length > 0) {
        let obj = list.filter((item) => {
          return item[key] == val
        })
        if (obj.length > 0) {
          return obj[0].name
        }
      }
      return null
    },

    // addCar() {
    //   this.$router.push("/addCar");
    // },
    goDetail(data) {
      this.$router.push({
        path: '/repairOrderDetail',
        query: { billId: data.billId },
      })
    },
    // 工单类型选择
    handleWorkSelect(index) {
      this.workBillTypeList[index].check = !this.workBillTypeList[index].check
    },
    // 工单类型重置
    handleWorkReset() {
      this.workBillTypeList.forEach((item) => {
        item.check = false
      })
    },
    // 时间筛选
    handleSelectTime(field) {
      this.timeField = field
      this.showPickerDate = true
    },
    // 时间确认
    onConfirmDate() {
      this.requestParams[this.timeField] = `${this.value1}-${this.value2}-${this.value3}` // 字符串拼接 结果入2020-07-03
      this.onCancelDate()
    },
    onCancelDate() {
      this.showPickerDate = false
    },
    clearSearch() {
      this.requestParams.codeNo = ''
      this.initData()
    },
    // 格式化多选数据
    formatCheckData(data) {
      data.forEach((item) => {
        item.check = false
      })
      return data
    },
    handleTel(tel) {
      if (isPhone()) {
        window.location.href = `tel:${tel}`
      } else {
        Toast('请在手机端使用此功能')
      }
    },
    onClickLeft() {
      localStorage.setItem('skipUrl', '')
      localStorage.setItem('repairOrderParam', '')
      this.$router.push('/home')
    },
    handleSearchReset() {
      this.workBillTypeList.forEach((item) => {
        item.check = false
      })

      this.requestParams = {
        ...this.requestParams,
        codeNo: '', //车架号或者车牌号，String，必填
        pageNo: 1, //当前页数，默认从1开始，每页显示十条，int，不能为空或者小于1
        startDateIn: getLastTimeYMD(), //进场开始时间，日期yyyy-MM-dd
        endDateIn: getTimeYMD(), //进场结束时间，日期yyyy-MM-dd
        startFinishDate: '', //完工开始时间，日期yyyy-MM-dd
        endFinishDate: '', //完工结束时间，日期yyyy-MM-dd
        startSettleTime: '', //结算开始时间，日期yyyy-MM-dd
        endSettleTime: '', //结算结束时间，日期yyyy-MM-dd
        workBillType: '', //工单类型，枚举
        serverPsnId: '', //维修中心ID
        serverPsnName: '', //维修中心ID
        fixCenterId: '', //服务顾问ID
        fixCenterName: '',
        personOrOrgId: '',
      }
    },
    // 顶部筛选选择数据
    handleSearchSelect(index, listKey, field) {
      this[listKey][index].check = !this[listKey][index].check
      console.log(this[listKey])
      let data = []

      this[listKey].forEach((el, ei) => {
        if (el.check) {
          data.push(el.value)
        }
      })

      this.requestParams[field] = data && data.length != 0 ? data.join(';') : ''
      console.log(this.requestParams)
    },
    // 展示筛选
    handleShowSearch() {
      this.searchVisible = true
    },

    handleSearchSave() {
      this.requestParams.pageNo = 1
      localStorage.setItem('repairSearchParam', JSON.stringify(this.requestParams))
      Toast('保存成功')
    },
    handleSearchConfirm() {
      this.initData()
      this.searchVisible = false
    },
    // 时间筛选
    handleSelectTime(field) {
      this.timeField = field
      this.showPickerDate = true
    },
    handleCopy(data) {
      copyToClipboard(data)
      Toast('复制成功')
    },
  },
}
</script>
<style>
html,
body {
  font-size: 50px !important;
  background: #fff;
  box-sizing: border-box;
}
</style>
<style lang="less" scoped="">
.home {
  background: #f2f2f2;
  //font-family: 'Alibaba';
}

.search_content {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 2;
}
.searchbox {
  padding: 0.3rem;
  .title {
    font-size: 0.3rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 0.4rem;
    padding-top: 0.2rem;
  }
  .insureList {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    .insure_item {
      text-align: center;
      padding: 0.15rem 0rem;
      width: 30%;
      box-sizing: border-box;
      font-size: 0.28rem;
      border-radius: 3px;
      color: #666;
      margin-bottom: 0.2rem;
      margin-right: 5%;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.5);
      &:nth-child(3n) {
        margin-right: 0;
      }
      &.active {
        box-shadow: 0px 0px 3px 0px #f65e07;
        color: #f65e07;
      }
    }
  }
  .insureBtn {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.4rem;
    .resetBtn {
      padding: 0 0.4rem;
      margin-right: 0.2rem;
    }
    .confirmBtn {
      padding: 0 0.4rem;
    }
  }
}

.orderList {
  margin: 0.2rem 0.2rem 0 0.2rem;
  overflow: hidden;

  .orderbox {
    width: 100%;
  }

  // padding-bottom: 1.5rem;
  .taskCheck {
    margin-right: 0.1rem;
  }

  .orderItem {
    padding: 11px 10px;
    background: #fff;
    border-radius: 5px;
    width: 100%;
    margin-bottom: 12px;

    // &:last-child {
    //   margin-bottom: 0;
    // }

    .orderItem_box {
      margin-bottom: 10px;
      padding-bottom: 8px;
      border-bottom: 1px solid rgba(216, 216, 216, 0.3);
      position: relative;

      .vinNobox {
        display: flex;
        align-items: center;
        margin-top: 4px;
        width: 100%;

        .customerName {
          margin-right: 13px;
          font-size: 0.24rem;
          color: #000;
        }
      }

      .vinNo {
        font-size: 0.24rem;
        color: #333;
        font-weight: bold;
        .icon-copy {
          font-size: 16px;
        }
      }
    }

    .orderItem_header {
      // display: flex;
      justify-content: space-between;
      align-items: center;

      .orderItem_lt {
        .carNo {
          display: flex;
          justify-content: space-between;
          font-size: 0.26rem;
          color: #333;
          font-weight: bold !important;
          align-items: center;
          .carNobox {
            display: flex;
            align-items: center;

            .txt {
              font-size: 13px;
              font-weight: bold !important;
              color: #333;
              .icon-edit {
                font-size: 14px;
                position: relative;
                top: -1px;
              }
              .icon-copy {
                font-size: 16px;
              }
            }
            .txt1 {
              font-size: 12px;
              color: #999;
            }
          }
        }

        .carStatus {
          background: rgba(14, 200, 89, 0.2);
          color: #187c17;
          border-radius: 4px;
          padding: 5px;
          font-size: 0.2rem;
          text-align: center;
          width: 1rem;
          margin-right: 5px;
        }
        .noCarStatus {
          background: rgba(255, 48, 33, 0.2);
          color: #ff1100;
          border-radius: 4px;
          padding: 5px;
          font-size: 0.2rem;
          text-align: center;
          width: 1rem;
          margin-right: 5px;
        }
      }

      .orderItem_rt {
        display: flex;
        align-items: center;
        align-self: center;
        justify-content: flex-start;
        color: #666;
        font-size: 0.24rem;

        .txt {
          font-size: 0.28rem;
          color: #161616;
        }

        .icon-tel {
          color: #fff;
          background: #35bc04;
          font-size: 0.32rem;
          padding: 0.1rem;
          border-radius: 50%;
          margin-right: 0.2rem;
        }

        .icon-wx {
          color: #409eff;
          font-size: 0.65rem;
        }
      }
    }

    .orderItem_content {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      align-items: center;
      // border-bottom: 1px solid rgba(216, 216, 216, 0.3);

      .orderItem_data {
        display: flex;
        justify-content: flex-start;
        align-items: center;
        width: 50%;
        margin-bottom: 6px;
        font-size: 0.28rem;
        box-sizing: content-box;
        color: #333;

        .order_label {
          font-size: 12px;
          color: #999;
          // width: 1.8rem;
        }
        .remark_con {
          font-size: 12px;
          color: #333;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          width: 4rem;
        }

        .txt {
          font-size: 0.24rem;
          color: #000;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          .icon-tips {
            font-size: 14px;
            margin-left: 2px;
            color: #929292;
          }
        }

        &.time {
          width: 100%;
        }
        &.remarkbox {
          justify-content: space-between;
          width: 7rem;
        }
        .remark_more {
          .icon-more {
            font-size: 0.28rem;
          }
        }
      }
    }

    .orderItem_label {
      .label_item {
        color: #fff;
        // border: 1px solid #35bc04;
        background: rgba(57, 117, 198, 1);
        border-radius: 2px;
        margin-right: 0.1rem;
        min-width: 0.4rem;
        padding: 4px 4px;
        text-align: center;
        font-size: 0.2rem;
        float: left;
        // margin-bottom: 0.1rem;
        margin-top: 8px;

        &:last-child {
          margin-right: 0;
        }
      }
    }

    .orderItem_file {
      margin-top: 5px;
      background: #ebebeb;
      color: #333;
      border-radius: 5px;
      padding: 5px 0;
      text-align: center;
      width: 100%;
      font-size: 13px;
      display: flex;
      align-items: center;
      justify-content: center;

      .file_item {
        width: 33.33%;
        border-right: 1px solid #ccc;
        display: flex;
        align-items: center;
        justify-content: center;

        .icon-tel {
          font-size: 17px;
          color: #959595;
          margin-right: 0.1rem;
        }

        .icon-mileage {
          font-size: 17px;
          color: #959595;
          margin-right: 0.1rem;
          position: relative;
          top: 0;
        }

        .icon-gw {
          font-size: 17px;
          color: #959595;
          margin-right: 0.1rem;
          position: relative;
          top: 0;
        }

        &:last-child {
          border: none;
        }
      }
    }
    .orderItem_footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-top: 1px solid rgba(216, 216, 216, 0.3);
      margin-top: 5px;
      padding-top: 10px;
      .item_icon {
        display: flex;
        .item_img {
          width: 20px;
          height: 20px;
          margin-left: 10px;
          border-radius: 50%;
          &:last-child {
            margin-right: 0;
          }
        }
      }
    }
  }
}

.addBtn {
  position: fixed;
  bottom: 0.8rem;
  width: 100%;
  z-index: 1;

  .orderItem_filebox {
    width: 2.8rem;
    margin: auto;
    text-align: center;
    font-size: 0.28rem;
    background: #409eff;
    color: #fff;
    padding: 0.25rem 0rem;
    border-radius: 50px;
  }
}

.noContent {
  margin-top: 2rem;
}
.contact_list {
  padding: 0.5rem 0.2rem 0 0.2rem;
  .contact_item {
    justify-content: space-between;
    margin-bottom: 20px;
  }
  .contact_lt {
    font-size: 0.28rem;
    color: #23ec1c;
    .contact_header {
      width: 30px;
      height: 30px;
      display: block;
      border-radius: 5px;
      margin-right: 5px;
    }

    .contact_name {
      font-size: 0.28rem;
      color: #333;
      margin-left: 5px;
    }
    .contact_com {
      color: #f65e07;
      font-size: 0.28rem;
    }
    .contact_com_wx {
      color: #23ec1c;
      font-size: 0.28rem;
    }
  }
  .contact_btn {
    background: #409eff;
    color: #fff;
    padding: 5px 15px;
    border-radius: 3px;
    font-size: 0.28rem;
  }
}
.task_header {
  height: 1.6rem;
  background: url('~@/assets/images/taskbg.png') no-repeat center;
  font-size: 0.24rem;
  background-size: 100% 100%;

  .top_title {
    position: relative;
    width: 100%;
    height: 50px;

    .top_title_back {
      position: absolute;
      left: 10px;
      line-height: 50px;
      color: #fff;
    }

    .top_title_val {
      text-align: center;
      line-height: 50px;
      color: #fff;
      font-weight: bold;
      font-size: 16px;
    }
    .onlyPerson {
      position: absolute;
      right: 10px;
      color: #fff;
      top: 13px;
      clear: both;
      .onlyPerson_txt {
        font-size: 12px;
        color: #fff;
        margin-bottom: 5px;
      }
      .onlyPerson_switch {
        float: right;
      }
    }
  }

  .task_header_data {
    position: relative;
    .top_arrow {
      background: rgba(255, 255, 255, 0.7);
      border-radius: 50%;
      width: 20px;
      height: 20px;
      line-height: 20px;
      text-align: center;
      color: #3975c6;
      opacity: 0.4;
    }
    .top_left {
      position: absolute;
      top: 22px;
      left: 10px;
      z-index: 3;
    }
    .top_right {
      position: absolute;
      top: 22px;
      right: 10px;
      z-index: 3;
    }
    .task_header_date {
      display: flex;
      align-items: center;
      width: 80%;
      margin: auto;
      margin-bottom: 10px;

      .task_header_date_w {
        width: 30px;
      }

      .task_header_date_item {
        width: calc((100% - 30px) / 5);
        text-align: center;
        color: #fff;
        font-size: 14px;
      }
    }

    .task_header_followData {
      display: flex;
      align-items: center;
      color: #fff;
      width: 80%;
      margin: auto;
      margin-bottom: 10px;

      .task_header_followData_tt {
        width: 30px;
        text-align: center;
      }

      .task_header_followData_item {
        width: calc((100% - 30px) / 5);
        text-align: center;
        font-size: 12px;
        font-weight: bold;
        &.active {
          position: relative;
          &::after {
            content: '';
            width: 30px;
            height: 2px;
            position: absolute;
            bottom: -7px;
            left: 50%;
            margin-left: -15px;
            background: #fff;
          }
          // border-bottom: 1px solid #fff;
        }
      }
    }
  }
}
.top_search {
  display: flex;
  align-items: center;
  background: #f2f2f2;
  width: 100%;
  justify-content: space-between;

  .top_search_val {
    width: 100%;
  }

  .top_search_icon {
    width: 120px;
    position: relative;
    top: 2px;

    img {
      width: 100%;
    }
  }
}
.w65 {
  width: 55% !important;
}
.w35 {
  width: 45% !important;
}
.w100 {
  width: 100% !important;
}
.no_icon {
  padding: 25px;
  padding-top: 100px;
  background: #fff;
  .no_icon_img {
    width: 70px;
    display: block;
    margin: auto;
  }
  .no_icon_txt {
    font-weight: 400;
    font-size: 14px;
    color: #86909c;
    text-align: center;
    margin-top: 10px;
  }
}
.search_info {
  position: relative;
  .pop_content {
    box-sizing: border-box;
    padding: 20px;
    background: #fff;
    position: fixed;
    width: 85%;
    height: 100vh;
    overflow: auto;
    right: 0;
    top: 0;
    z-index: 11;
    padding-bottom: 60px;
  }
}
.mask {
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 10;
}

.popSearch {
  font-size: 12px;
  width: 100%;
  padding-top: 20px;

  .popSearchbox {
    width: 100%;

    .popSearchbox_item {
      margin-bottom: 10px;

      .popSearch_tt {
        font-size: 0.24rem;
        font-weight: bold;
        margin-bottom: 12px;
        .tips {
          color: #ff4444;
        }
      }

      .popSearch_time {
        display: flex;
        align-items: center;

        .popSearch_time_txt {
          width: 45%;
          .popSearch_time_val {
            background: #f9f9f9;
            border-radius: 30px;
            text-align: center;
            padding: 7px 0;
            display: block;
            width: 100%;
          }
        }

        .popSearch_time_icon {
          margin: 0 10px;
        }
      }

      .popSearchbox_selectList {
        display: flex;
        flex-wrap: wrap;
        width: 100%;

        .popSearchbox_select_item {
          box-sizing: border-box;
          width: 32%;
          font-size: 0.2rem;
          padding: 7px 0;
          color: #4b4b4b;
          text-align: center;
          margin-right: 2%;
          margin-bottom: 12px;
          background: #f9f9f9;
          border-radius: 20px;
          border: 1px solid #f9f9f9;

          &:nth-child(3n) {
            margin-right: 0;
          }

          &.active {
            color: #ff4444;
            background: #ffd8d3;
            border-radius: 62px 62px 62px 62px;
            border: 1px solid #dd5953;
          }
        }
      }
      /deep/ .van-cell {
        padding: 5px 0;
        font-size: 0.22rem;
        color: #4b4b4b;
      }
      /deep/ .van-cell::after {
        border: none;
      }
    }
  }
  .popSearch_footer {
    box-sizing: border-box;
    background: #fff;
    display: flex;
    padding: 10px 20px;
    width: 85%;
    z-index: 99;
    position: fixed;
    right: 0;
    bottom: 0;
    .popSearch_btn {
      font-size: 15px;
      box-sizing: border-box;
      width: 28%;
      padding: 10px 0;
      border-radius: 50px;
      margin-right: 8%;
      text-align: center;
      &:nth-child(3n) {
        margin-right: 0;
      }
      &.reset_btn {
        color: #dc2326;
        border: 1px solid #dd5953;
      }
      &.save_btn {
        color: #fff;
        background: linear-gradient(316deg, #3975c6 0%, #71a4ea 100%);
      }
      &.confirm_btn {
        color: #fff;
        background: linear-gradient(316deg, #3975c6 0%, #71a4ea 100%);
      }
    }
  }
}
</style>
<style scoped>
/deep/ .van-search {
  background: #f2f2f2;
}

/deep/ .van-pull-refresh {
  margin-top: 99px;
}
</style>
